<template>
  <div class="liantong-main-con">
    <div class="liantong_title">
      <span>连通分析</span>
    </div>
    <div class="tootipText">
      <div class="tooltipbg"></div>
      <span>请在地图上选择需要两处管线</span>
    </div>
    <div class="btnGroup1">
      <div
        :class="[isBtnActive ? 'handleBtnActive' : 'handleBtnUnactive']"
        @click="ltfxstart"
      >
        <span>请选择管线</span>
      </div>
      <!-- <div class="clearResult" @click="bgfxend">
        <span>清除事故点</span>
      </div> -->
    </div>
    <div v-for="(item, i) in lonlat" :key="i" class="choseGuanXianResult">
      <span>{{ item.properties.name }}</span>
      <div class="deleteResult" @click="deletedata(i)"></div>
      <!-- <button @click="deletedata(i)">删除</button> <br> -->
    </div>

    <div class="btnGroup" v-show="lonlat.length == 2">
      <div class="handleBtn" @click="ltfxend">
        <span>重置</span>
      </div>
      <div class="clearResult" @click="getData">
        <span>分析</span>
      </div>
    </div>
    <!-- <div class="liantong_form" style="color: #00baff;">
      <button @click="ltfxstart">选择管线</button>
      <button @click="ltfxend">重置</button>
      <button @click="getData">分析</button> -->
    <!-- <button>查询</button> -->
    <!-- <div v-for="(item,i) in lonlat" :key="i">
        <span>{{item.properties}}</span> <button @click="deletedata(i)">删除</button> <br>
      </div> -->
    <!-- </div> -->

    <div class="liantong_result" v-show="isShowResult">
      <!-- <div class="liantong_result_line"></div> -->
      <div class="liantong_result_title">
        <span>查询结果</span>
      </div>
      <div style="color: #ffffff" class="baoGuanResultItem">
        <div class="analysisResult">
          <span v-if="type == 0"></span>
          <span v-if="type == 1">分析结果：不连通</span>
          <span v-if="type == 2">分析结果：连通</span>
        </div>
        <div class="resultList">
          <div class="resultItemContent">
            <div class="resultItem" v-for="(item, i) in data" :key="i">
              <span>{{ item.name }}</span>
            </div>
          </div>
        </div>
        <!-- <span>{{ data }}</span> -->
      </div>
    </div>
  </div>
</template>

<script>
import Bus from "@/js/EventBus";
import { getshortPathData, getBoxLineData } from "@/api/http";
export default {
  name: "LianTongAnalysis",
  components: {},
  data() {
    return {
      valueMultiple: [],
      data: null,
      type: 0,
      lonlat: [],
      isBtnActive: false,
      isShowResult: false,
    };
  },

  mounted() {
    let that = this;
    this.isBtnActive = false;
    Bus.$on("ltfxdata", (e) => {
      // console.log(e);
      // this.clearAllDrawn();
      // this.getData(e);
    });
    Bus.$on("ltfxid", (e) => {
      // 查询
      this.searchIdData(e);
    });
    // Bus.$on("ltfxlonlat", (e,) => {
    //   // console.log(e, "e============")
    // });
  },
  methods: {
    async searchIdData(id) {
      let ID = JSON.parse(id);
      const res = await getBoxLineData(`UserID='${ID.UserID}'`);
      console.log(res, "res=======================");
      this.lonlat.push(res.features[0]);
    },
    deletedata(i) {
      console.log(this.lonlat[i]);
      let id = this.lonlat[i].properties.UserID;
      // Bus.$emit("ltfxdelete", id);
      Bus.$emit("removelinecolor", id);
      this.lonlat.splice(i, 1);
    },
    ltfxstart() {
      Bus.$emit("ltfx", true);
      this.isBtnActive = true;
    },
    ltfxend() {
      Bus.$emit("ltfx", false);
      this.type = 0;
      this.data = null;
      this.lonlat = [];
      this.isBtnActive = false;
      this.isShowResult = false;
    },

    async getData() {
      // alert(e)
      if (this.lonlat.length == 2) {
        let params = [];
        // .properties.source
        this.lonlat.forEach((element) => {
          // console.log(element)
          params.push(element.properties.source);
        });
        console.log(params, "params");
        // console.log(e.flat())
        // let params = e.flat()
        // let params = []
        const { data: res } = await getshortPathData(params.flat());
        console.log(res);

        if (res == null) {
          this.type = 1;
          this.data = [];
          this.isShowResult = true;
        } else {
          this.type = 2;
          this.data = res;
          this.isShowResult = true;

          res.forEach((element) => {
            let idData = {
              UserID: element.userid,
            };
            Bus.$emit("addlinecolor", JSON.stringify(idData));
          });
          // Bus.$emit("ltfxlineHeight", res);
        }
      } else {
        this.$Message.error("所选数据长度应为2");
        // alert('shujuchangdubuwei2')
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.liantong-main-con {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 301px;
  height: 712px;
  background: url("../../assets/rightMenu/selectInfo/selectInfo_bg.png");
  background-size: 100% 100%;
}

.liantong_title {
  width: 280px;
  height: 35px;
  box-sizing: border-box;
  background: url("@/assets/panelTree/dtml_bg_title.png") no-repeat;
  font-family: SourceHanSansCN-Regular;
  font-size: 14px;
  background-size: 100% 100%;
  text-align: left;
  padding-left: 50px;
  line-height: 34px;
  // background-color: red;
  margin: 10px 0 0 10px;
}

.tootipText {
  display: flex;
  flex-direction: row;
  padding: 10px 20px 0 20px;
  align-items: center;

  .tooltipbg {
    width: 16px;
    height: 16px;
    background: url("@/assets//panelTree/tooltip.png");
    margin-right: 10px;
    background-size: 98% 98%;
  }

  span {
    font-size: 12px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 28px;
    letter-spacing: 1px;
    color: #95b0c2;
  }
}

.btnGroup1 {
  padding: 0 30px 10px 10px;

  .handleBtnActive {
    width: 100px;
    height: 28px;
    background: url(../../assets/panelTree/btn-check.png);
    text-align: center;
    margin: 0 0 0 10px;
    cursor: pointer;

    span {
      font-family: SourceHanSansCN-Medium;
      font-size: 12px;
      font-weight: normal;
      font-stretch: normal;
      line-height: 28px;
      letter-spacing: 1px;
      color: #00baff;
    }
  }

  .handleBtnUnactive {
    width: 100px;
    height: 28px;
    background: url(../../assets/panelTree/btn-uncheck.png);
    text-align: center;
    margin: 2px 0 0 10px;
    cursor: pointer;

    span {
      font-family: SourceHanSansCN-Medium;
      font-size: 12px;
      font-weight: normal;
      font-stretch: normal;
      line-height: 28px;
      letter-spacing: 1px;
      color: #ffffff;
    }
  }

  .handleBtn,
  .clearResult {
    width: 100px;
    height: 28px;
    background: url(../../assets/panelTree/btn-uncheck.png);
    text-align: center;
    margin: 10px 0 0 10px;
    cursor: pointer;

    span {
      font-family: SourceHanSansCN-Medium;
      font-size: 14px;
      font-weight: normal;
      font-stretch: normal;
      line-height: 28px;
      letter-spacing: 1px;
      color: #fff;
    }
  }
}

.btnGroup {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 30px 10px 30px;
  text-align: center;

  .handleBtn,
  .clearResult {
    width: 100px;
    height: 28px;
    background: url(../../assets/panelTree/btn-uncheck.png);
    text-align: center;
    margin: 10px 0 0 10px;
    cursor: pointer;
  }

  span {
    font-family: SourceHanSansCN-Medium;
    font-size: 12px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 28px;
    letter-spacing: 1px;
    color: #fff;
  }
}

.choseGuanXianResult {
  margin: 8px 30px 0 20px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;

  span {
    font-family: SourceHanSansCN-Regular;
    font-size: 12px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 24px;
    letter-spacing: 0px;
    color: #daf0ff;
  }

  div {
    width: 13px;
    height: 17px;
    background: url(../../assets/panelTree/delete.png);
    // margin: 0 20px 0 10px;
  }
}

.baoGuanResultItem {
  // margin: 10px 30px 0 20px;
  /* width: 200px; */
  /* text-align: left; */
  font-family: SourceHanSansCN-Regular;
  font-size: 16px;
  font-weight: normal;
  font-stretch: normal;
  /* line-height: 18px; */
  letter-spacing: 0px;
  color: #daf0ff;
  /* padding-left: 6px; */
}

.liantong_title span {
  font-family: SourceHanSansCN-Regular;
  font-size: 14px;
  color: #c8e9ff;
}

.liantong_result_title {
  width: 300px;
  height: 16px;
  background: url("../../assets/rightMenu/selectInfo/monitor_form_title.png")
    0px 2px no-repeat;
  text-align: center;
  color: #00baff;
  margin-bottom: 20px;
}

.liantong_result_title span {
  font-family: SourceHanSansCN-Regular;
  font-size: 14px;
  line-height: 12px;
}

.liantong_result {
  margin-top: 10px;
  flex: 1;
}

.liantong_result_line {
  width: 289px;
  height: 1px;
  background: url(../../assets/rightMenu/selectInfo/boundary_line.png);
  background-size: 100% 100%;
  margin-bottom: 20px;
}

::v-deep {
  .el-form-item__label {
    font-family: SourceHanSansCN-Regular !important;
    font-size: 14px !important;
    line-height: 44px !important;
    color: #daf0ff !important;
    padding: 0 0 0 16px !important;
  }
}

.analysisResult {
  text-align: left;
  margin-left: 20px;
  margin-bottom: 10px;
  span {
    font-size: 14px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 28px;
    letter-spacing: 1px;
    color: #fff;
  }
}

.resultList {
  padding-left: 20px;
  overflow-y: auto;
  height: 340px;
  margin-right: 10px;

  .resultItemContent {
    .resultItem {
      cursor: pointer;
    }

    span {
      font-size: 12px;
      font-weight: normal;
      font-stretch: normal;
      line-height: 28px;
      letter-spacing: 1px;
      color: #95b0c2;
    }
  }

  &::-webkit-scrollbar {
    width: 4px;
    height: 1px;
    background: rgba(9, 85, 133, 0.8);
    display: block;
    border-radius: 3px;
  }

  /*滚动条里面小方块*/
  &::-webkit-scrollbar-thumb {
    border-radius: 5px;
    background: #052149;
  }

  /*滚动条里面轨道*/
  &::-webkit-scrollbar-track {
    border-radius: 3px;
    background: transparent;
  }
}
</style>
